"""
# Definition for a Node.
"""
import collections
class Node(object):
    def __init__(self, val, children):
        self.val = val
        self.children = children



class Solution(object):
    def levelOrder(self, root):
        """
        :type root: Node
        :rtype: List[List[int]]
        """
        if not root:
            return [[]]
        a = []
        queue = collections.deque()
        queue.append((root,0))
        while queue:
            node,level =  queue.popleft()
            if node:
                if len(a) < level + 1:
                    a.append([])
                a[(level)].append(node.val)
                for child in node.children:
                    queue.append((child,level+1))